﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WFBASE
{
    /// <summary>
    /// 實用工具類
    /// </summary>
    public class Util
    {
        /// <summary>
        /// 添加並檢查SQL條件
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        public static string AddEQSqlParam(string name, string value, string prefix)
        {
            if(value.Trim()!="")
                return " "+prefix + " " + name + "='" + FormatSqlStr(value) + "'";
            return "";
        }
        public static string AddLikeSqlParam(string name, string value, string prefix)
        {
            if(value.Trim()!="")
                return " "+prefix + " " + name + " like '" + FormatSqlStr(value) + "%'";
            return "";
        }
        /// <summary>
        /// 處理SQL中的特殊字符
        /// </summary>
        /// <param name="p_String"></param>
        /// <returns></returns>
        public static string FormatSqlStr(string p_String)
        {
            if (p_String == null || p_String.Trim() == "")
                return "";
            string result = p_String.Replace("'", "''");
            return result;
        }

    }
}
